package com.example.lambda;

import java.util.Comparator;
import java.util.function.Consumer;

public class LambdaLearn {

    public static void main(String[] args) {

        //1.没有参数，没有返回值
        Runnable r1 = new Runnable() {
            @Override
            public void run() {
                System.out.println("hello world");
            }
        };
        r1.run();
        Runnable r2 = () -> System.out.println("hello world");

        //2.有一个参数，没有返回值
        Consumer<String> c1 = new Consumer<String>() {
            @Override
            public void accept(String s) {
                System.out.println(s);
            }
        };
        c1.accept("hello world");

        Consumer<String> c2 = (String s) ->{
            System.out.println(s);
        };
        c1.accept("hello world");


        //3.省略参数类型，类型推断
        Consumer<String> c3 = new Consumer<String>() {
            @Override
            public void accept(String s) {
                System.out.println(s);
            }
        };
        c3.accept("hello world");

        Consumer<String> c4 = (s) ->{
            System.out.println(s);
        };
        c4.accept("hello world");


        //4.只有一个参数，参数括号省略
        Consumer<String> c5 = (s) ->{
            System.out.println(s);
        };
        c4.accept("hello world");

        Consumer<String> c6 = s ->{
            System.out.println(s);
        };
        c4.accept("hello world");

        //5.两个或两个以上参数，且有返回值
        Comparator<Integer> com1 = new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o1.compareTo(o2);
            }
        };

        Comparator<Integer> com2 = (o1,o2) -> {
            return o1.compareTo(o2);
        };


        //6.只有一条语句时候，return 和 大括号省略
        Comparator<Integer> com3 = (o1,o2) -> {
            return o1.compareTo(o2);
        };

        Comparator<Integer> com4 = (o1,o2) -> (o1.compareTo(o2));




    }

}
